package com.ddf.publics.service.impl;

import com.ddf.publics.entity.Commodity;
import com.ddf.publics.dao.CommodityDao;
import com.ddf.publics.entity.Page;
import com.ddf.publics.service.CommodityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Commodity)表服务实现类
 *
 * @author makejava
 * @since 2020-06-17 09:54:28
 */
@Service
public class CommodityServiceImpl implements CommodityService {
    @Resource
    private CommodityDao commodityDao;

    @Override
    public List<Map> dainziList(Page page) {
        if(page.getLimit()==null||page.getCount()==null){
            return null;
        }else {
            return commodityDao.dainziList(page.getLimit(), page.getCount());
        }

    }

    @Override
    public List<Map> shiwuList(Page page) {
        if(page.getLimit()==null||page.getCount()==null){
            return null;
        }else {
            return commodityDao.shiwuList(page.getLimit(), page.getCount());
        }
    }

    @Override
    public List<Map> lifeList(Page page) {
        if(page.getLimit()==null||page.getCount()==null){
            return null;
        }else {
            return commodityDao.lifeList(page.getLimit(), page.getCount());
        }
    }

    @Override
    public int dainziListCount() {
        return commodityDao.dainziListCount();
    }

    @Override
    public int shiwuListCount() {
        return commodityDao.shiwuListCount();
    }

    @Override
    public int lifeListCount() {
        return commodityDao.lifeListCount();
    }

    @Override
    public int commodityCount() {
        return commodityDao.commodityCount();
    }

    /**
     * 通过ID查询单条数据
     *
     * @param goodsId 主键
     * @return 实例对象
     */
    @Override
    public Commodity queryById(Integer goodsId) {
        return this.commodityDao.queryById(goodsId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Commodity> queryAllByLimit(int offset, int limit) {
        return this.commodityDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param commodity 实例对象
     * @return 实例对象
     */
    @Override
    public Commodity insert(Commodity commodity) {
        this.commodityDao.insert(commodity);
        return commodity;
    }

    /**
     * 修改数据
     *
     * @param commodity 实例对象
     * @return 实例对象
     */
    @Override
    public Commodity update(Commodity commodity) {
        this.commodityDao.update(commodity);
        return this.queryById(commodity.getGoodsId());
    }

    /**
     * 通过主键删除数据
     *
     * @param goodsId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer goodsId) {
        return this.commodityDao.deleteById(goodsId) > 0;
    }
}